(function(){
	angular.module('webApp').controller("FenxiaopriceCtrl",FenxiaopriceCtrl);
	FenxiaopriceCtrl.$inject=['$scope','dataService','$location','$state','helper'];
	function FenxiaopriceCtrl($scope,dataService,$location,$state,helper){
		$scope.listAction=function(){
			$scope.page_Size=10;
			$scope.getFenxiaopriceList(1);
		}
		$scope.getFenxiaopriceList=function(page_No){
			var query={page_no:page_No,page_size:$scope.page_Size};
			dataService.fenxiaopriceGet(query).then(function(result){
				if(result.Msg){
					helper.myAlert("error:"+result.Msg);
				}else{
					// helper.myAlert("success",null,null,function(){
							$scope.fenxiaoprices=result.shop;
							$scope.fenxiaopricesTotal=result.total_count;
					// });
				}
			});
		}	
		$scope.addAction=function(){
			var id=$location.search().id;
			if(id){
				dataService.fenxiaopriceOne(id).then(function(r){
					if(r.Msg){
						helper.myAlert("error:"+r.Msg);
					}else{
						$scope.fenxiaoprice=r;
					}
				});
			}
		}
		$scope.infoAction=function(){
			var id=$location.search().id;
			if(id){
				dataService.fenxiaopriceOne(id).then(function(r){
					if(r.Msg){
						helper.myAlert("error:"+r.Msg);
					}else{
						$scope.fenxiaoprice=r;
					}
				});
			}

		}
		$scope.FenxiaopriceAdd=function(){
			if($scope.fenxiaoprice.id){
				dataService.fenxiaopriceUpdate($scope.fenxiaoprice).then(function(result){
					if(result.Msg){
						helper.myAlert("error:"+result.Msg);
					}else{
						helper.myAlert("success",null,null,function(){
							$state.go("fenxiaoprice.list");
						});
					}
				})
			}else{
				dataService.fenxiaopriceAdd($scope.fenxiaoprice).then(function(result){
					if(result.Msg){
						helper.myAlert("error:"+result.Msg);
					}else{
						helper.myAlert("success",null,null,function(){
							$state.go("fenxiaoprice.list");
						});
					}
				})
			}
		}
		$scope.FenxiaopriceDelete=function(id){
			dataService.fenxiaopriceDelete(id).then(function(result){
					if(result.Msg){
						helper.myAlert("error:"+result.Msg);
					}else{
						helper.myAlert("success",null,null,function(){
							$scope.listAction();
						});
					}
			})
		}
	};
})();